import { cloneDeep } from 'lodash-es';
import {
  REALM_BIG_LEVEL_NUMBER_MAP,
  REALM_BIG_LEVEL_TYPE_NAME_MAP,
  REALM_LEVEL_LIST,
  type RealmBigLevelType,
  type RealmLevel,
} from '../../data/realm';

export class RealmReader {
  static getRealmNumber(rt: RealmBigLevelType): number {
    return REALM_BIG_LEVEL_NUMBER_MAP[rt];
  }

  static getRealmConfigByLevel(level: number): RealmLevel {
    const maxLevel = Math.max(REALM_LEVEL_LIST.length - 1, 0);
    const currentLevel = Math.min(level, maxLevel);
    const config = REALM_LEVEL_LIST[currentLevel];
    if (config) {
      return config;
    }
    return cloneDeep(REALM_LEVEL_LIST[0]!);
  }

  static getRealmDisplayName(realm: RealmBigLevelType): string {
    return REALM_BIG_LEVEL_TYPE_NAME_MAP[realm];
  }
}
